#pragma once
#include "type_cpp14.h" 
#include "IByteStream.h" 

namespace Serial_Port {
	using IByteStream = lee8871_byte::IByteStream;
	enum eSerialPortErr {
		set_name_while_port_opened = -300, 
		try_table_max,
		open_port_fail,
		setting_port_fail,
		set_name_too_long,
		send_while_port_closed,
		recv_while_port_closed,
		bad_receive_len,
	};

	class __EXPORT_DLL SerialPort: public IByteStream {
	private:
		class Impl;
		std::unique_ptr<Impl> pimpl;
	public:
		SerialPort();
		~SerialPort();
		error_code setPort(char const* ch);
		error_code setBaud(int baud);
		error_code openPort();
		error_code closePort();

		bool isRunning();
		error_code send(byte const* b, int length);
		error_code recv(byte* b, int& length, int max_length);
	};
}